﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utils.MathUtilitys;
using Utils.Misc;

namespace Utils.App
{
    public class Mode
    {
        public const int MODE_Active = 0;
        public const int MODE_Init = -1;
        public const int MODE_Inactive = -2;
        public const int MODE_Dead = -3;

        #region Fields

        Timer timer = new Timer();
        int mode = MODE_Init;

        #endregion

        #region Properties

        public Timer Timer { get { return timer; } }

        #endregion

        #region Initialization

        public Mode() { }

        public Mode(int mode)
        {
            Set(mode);
        }

        public Mode(int mode, float time)
        {
            Set(mode, time);
        }

        #endregion

        #region Methods

        public void Set(int mode)
        {
            this.mode = mode;
        }

        public void Set(int mode, float time)
        {
            this.mode = mode;
            timer.Set(time);
        }

        public void Set(int mode, RangeValue<float> time)
        {
            this.mode = mode;
            timer.Set(RndUtils.RndfInRange(time));
        }

        public void SetInactive()
        {
            this.mode = MODE_Inactive;
        }

        public bool IsActive()
        {
            return mode >= 0;
        }

        public bool Test(int mode)
        {
            return this.mode == mode;
        }

        public bool TestWithTimeout(int mode)
        {
            return this.mode == mode && timer.Current <= 0;
        }

        public bool IsTimeout()
        {
            return timer.Current <= 0;
        }

        public void Update(float dTime)
        {
            timer.Update(dTime);
        }

        #endregion
    }
}
